unit DesktopWallPaper;

interface

uses
  Windows, SysUtils, Registry, Classes;

Procedure SetWallpaperExt(sWallpaperBMPPath: String; nStyle, nX, nY:  Integer);

Const
  WPS_Tile = 0; { Tile Wallpaper }
  WPS_Center = 1; { Center wallpaper }
  WPS_SizeToFit = 2; { Resize the wallpaper to match current resolution }
  WPS_XY = 3; { Place the picture at the given location }



Implementation


Procedure SetWallpaperExt(sWallpaperBMPPath: String; nStyle, nX, nY:  Integer);
Var
  h: HWND;
  reg: TRegIniFile;
  s1: String; { 0 = Stretch, 1 = No Stretch }
  x, y: Integer; { x,y location of bitmap }
Begin
  reg := TRegIniFile.Create('Control Panel\Desktop');
  s1 := '0';
  x := 0;
  y := 0;
  Case nStyle Of
    WPS_Tile: s1 := '1';
    WPS_Center: nStyle := WPS_Tile;
    WPS_XY:
      Begin
        nStyle := WPS_Tile;
        x := nX;
        y := nY;
      End;
  End;
  reg.WriteString('', 'Wallpaper', sWallpaperBMPPath);
  reg.WriteString('', 'TileWallpaper', s1);
  reg.WriteString('', 'WallpaperStyle', IntToStr(nStyle));
  reg.WriteString('', 'WallpaperOriginX', IntToStr(X));
  reg.WriteString('', 'WallpaperOriginY', IntToStr(Y));
  reg.Free;
  SystemParametersInfo(
    SPI_SETDESKWALLPAPER,
    0,
    PChar(sWallpaperBMPPath),
    SPIF_UPDATEINIFILE Or SPIF_SENDWININICHANGE);
End;

end.
